<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page trimDirectiveWhitespaces="true" %>
<%String path = request.getContextPath();%>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="<%=path%>/static/layui/css/layui.css" rel="stylesheet">
    <link href="<%=path%>/static/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
</head>

<body>

<form class="layui-form" method="post"  action="<%=path%>/system/menu/save" lay-filter="formDemo" style="margin-top: 40px;width: 600px;" id="data">
    <div class="layui-form-item">
        <label class="layui-form-label">上级菜单：</label>
        <div class="layui-input-block">
            <!--菜单id-->
            <input type="hidden"  id="id" name="id" value="<c:if test="${not empty edit}"> ${edit.id}</c:if>"/>
            <!--上级菜单-->
            <input id="parentId" type="text" readonly="true"   autocomplete="off"
                   value=
                   "<c:choose>
                          <c:when test="${not empty edit}"> ${edit.parent.name}</c:when>
                         <c:when test="${not empty parentAdd}"> ${parentAdd.name}</c:when>
                         <c:when test="${not empty add}"> ${add.name}</c:when>
                    </c:choose>"
                   data-id=
                       "<c:choose>
                           <c:when test="${not empty edit}"> ${edit.parent.id}</c:when>
                         <c:when test="${not empty parentAdd}"> ${parentAdd.id}</c:when>
                         <c:when test="${not empty add}"> ${add.id}</c:when>
                        </c:choose>"
                   class="layui-input" onclick="menuTreeClick()" lay-verify="required">
            <input type="hidden" name="parentId" id="parentIdValue"
                   value="<c:choose>
                        <c:when test="${not empty edit}"> ${edit.parent.id}</c:when>
                         <c:when test="${not empty parentAdd}"> ${parentAdd.id}</c:when>
                         <c:when test="${not empty add}"> ${add.id}</c:when>
                    </c:choose>">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">新增菜单名：</label>
        <div class="layui-input-block">
            <input type="text" name="name" autocomplete="off"
                   value="<c:if test="${not empty edit}"> ${edit.name}</c:if>"
                   class="layui-input"  lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">显示顺序：</label>
        <div class="layui-input-block">
            <input type="text" name="sort" autocomplete="off"
                   value="<c:if test="${not empty edit}"> ${edit.sort}</c:if>"
                   class="layui-input" id="sort" lay-verify="number">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单类型：</label>
        <div class="layui-input-block">
            <select name="type" lay-verify="required">
                <option value=""></option>
                <option value="M" <c:if test="${not empty edit}"> ${edit.type=="M"?"selected":""}</c:if>>目录</option>
                <option value="L" <c:if test="${not empty edit}"> ${edit.type=="L"?"selected":""}</c:if>>连接</option>
                <option value="B" <c:if test="${not empty edit}"> ${edit.type=="B"?"selected":""}</c:if>>按钮</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">打开方式：</label>
        <div class="layui-input-block">
            <select name="target" lay-verify="required">
                <option value=""></option>
                <c:forEach items="${urlList}" var="urlType">
                    <option value="${urlType.id}"  <c:if test="${not empty edit}"> ${edit.target==urlType.id?"selected":""}</c:if>>${urlType.dictValue}</option>
                </c:forEach>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">图标：</label>
        <div class="layui-input-block">
            <input type="text" name="imageUrl" autocomplete="off"
                    placeholder="格式如fa-home"
                   value="<c:if test="${not empty edit}"> ${edit.imageUrl}</c:if>"
                   class="layui-input" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">key：</label>
        <div class="layui-input-block">
         <input type="text" name="key" autocomplete="off"
            value="<c:if test="${not empty edit}"> ${edit.key}</c:if>"
            class="layui-input" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">请求地址：</label>
            <div class="layui-input-block">
                <input type="text" name="requestUrl" autocomplete="off"
                    value="<c:if test="${not empty edit}"> ${edit.requestUrl}</c:if>"
                    class="layui-input" lay-verify="required">
            </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">权限字符串：</label>
        <div class="layui-input-block">
            <input type="text" name="perms" autocomplete="off"
                value="<c:if test="${not empty edit}"> ${edit.perms}</c:if>"
                class="layui-input" lay-verify="required">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">是否可见：</label>
        <div class="layui-input-block">
            <input type="checkbox" name="visible" lay-skin="switch" lay-text="可见|不可见" value="0"
             <c:if test="${not empty edit && edit.visible==0}">checked</c:if>
            >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否停用：</label>
        <div class="layui-input-block">
            <input type="checkbox" name="enable" lay-skin="switch" lay-text="正常|禁用" value="0"
            <c:if test="${not empty edit && edit.enable==0}">checked</c:if>
            >
        </div>
    </div>
    <button id="departSubmit" class="layui-btn" lay-filter="formVerify" lay-submit style="display: none">添加</button>

</form>
<script src="<%=path%>/static/layui/layui.all.js"></script>
<script src="<%=path%>/static/js/jquery.min.js?v=2.1.4"></script>
<script src="<%=path%>/static/myjs/MyLayer.js"></script>
<script>
//初始化
var layer=window.top.layer;
layui.use(['form'], function () {
    let form=layui.form
    form.on('submit(formDemo)', function(data){
        layer.closeAll("iframe")
    });
})

//点击显示菜单树
function menuTreeClick() {
    MyLayer.iframeLayer(layer,"请选择上级菜单","<%=path%>/system/menu/menuTree",{
        "确定":function (index) {
            let brotherIframe= parent['layui-layer-iframe' +index]
            let node=brotherIframe.myTree.getSelectedNodes();
            if (node.length==0){
                return true;
            }
            let obj=node[0];
            window.$("#parentId").val(obj.name)
            window.$("#parentIdValue").val(obj.id)
        }
    },"small")
}

</script>
</body>

</html>